const shpwrite = require('shp-write');
const fs = require('fs');
const path = require('path');

// 测试GeoJSON数据
const testGeoJSON = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "测试点1",
        "type": "商店"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [116.3974, 39.9093]
      }
    }
  ]
};

console.log('开始测试shp-write...');

// 测试1: 使用write方法
shpwrite.write(testGeoJSON, 'test1', {
  folder: 'D:/download',
  types: {
    point: 'points',
    polygon: 'polygons',
    line: 'lines'
  }
}, (err, files) => {
  if (err) {
    console.error('write方法失败:', err);
  } else {
    console.log('write方法成功:', files);
  }
});

// 测试2: 使用zip方法
try {
  const zipBuffer = shpwrite.zip(testGeoJSON);
  console.log('zip方法成功，buffer长度:', zipBuffer.length);
  
  // 写入zip文件
  fs.writeFileSync('D:/download/test2.zip', zipBuffer);
  console.log('zip文件已保存到 D:/download/test2.zip');
} catch (error) {
  console.error('zip方法失败:', error);
}

console.log('测试完成');